package api

import (
	"github.com/gin-gonic/gin"
)

func InitRouter() {
	engine := gin.Default()

	engine.LoadHTMLGlob("./html/*")

	engine.GET("/", func(ctx *gin.Context) {
		ctx.HTML(200, "index.html", gin.H{
			"title": "Hello OAuth!",
		})
	})

	engine.GET("/usr", func(ctx *gin.Context) {
		username, ok := ctx.GetQuery("username")

		if !ok {
			ctx.String(500, "未知错误")
			ctx.Abort()
			return
		}

		ctx.String(200, "登录成功! 欢迎你 "+username)
	})

	engine.GET("/oauth/callback", oauth)

	engine.Run(":80")
}
